<?php 
require_once substr(dirname(__FILE__),0,-1).'sub/init.php';
require_once ZEAI.'sub/conn.php';
require_once ZEAI.'m/my_chk_u.php';
/***********************主体入口***************************/
$fid = intval($fid);
if(!ifint($fid)){alert('参数丢失',"lovetest.php");}else{
	$rowS = $db->ROW(__TBL_LOVETEST_BANK__,"price,uids","id=".$fid,'name');
	if ($rowS){
		$price = $rowS['price'];
		$uids = dataIO($rowS['uids'],'out');
		$uidsArr = explode(",",$uids);
		if($price!=0 && !in_array($cook_uid,$uidsArr)){alert('此套试题需要付费，请先付费！',"qinggan_ifpay.php?fid=".$fid);}
	}else{alert('试题库不存在或已经删除',"lovetest.php");}
}
//
if($submitok=="ajax_save"){
	$rt = $db->query("SELECT id FROM ".__TBL_LOVETEST_QUESTION__." WHERE kind=".$fid." ORDER BY id DESC");
	$total = $db->num_rows($rt);
    if ($total > 0 ) {
		$tmpArr = array();
		$all_answer = array();
		$score = 0;
		for($i=1;$i<=$total;$i++) {
			$rows = $db->fetch_array($rt);
			if(!$rows) break;
			$id = $rows['id'];
			$tmp_question = ${"question".$id};
			if(empty($tmp_question))json_exit(array('flag'=>0,'msg'=>"请填写完测试题再提交！"));

			$answer = '';
			for($j=0;$j<count($tmp_question);$j++){
				$tmpQarr = explode(":",$tmp_question[$j]);
				if($j==count($tmp_question)-1){$answer .= $tmpQarr[0];}else{$answer .= $tmpQarr[0].",";}
				$score += intval($tmpQarr[1]);
			}
			array_push($all_answer,$answer);
		}
		$all_answer = implode("|",$all_answer);
		$db->query("INSERT INTO ".__TBL_LOVETEST_ANSWER__." (qid,uid,score,answer,addtime) VALUES ('$fid','$cook_uid','$score','$all_answer',".ADDTIME.")");
	}
	json_exit(array('flag'=>1,'msg'=>"测试完成，正在跳转查看结果..."));
}
$headertitle = '情感测试';?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $headertitle;?></title>
<?php echo HEADMETA; ?>
<meta name="x5-orientation" content="portrait">
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/qinggan.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<style>
#backtop a,#btmKefuBtn,.detail_agree .button{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.nextbtn {
    width: 100%;
    max-width: 750px;
    height: 9rem;
    padding-top: 1.5rem;
    position: fixed;
    bottom: 0;left:0;right:0;margin:auto;
    background-color: #fff;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    z-index: 889;
}
.nextbtn button {
    width: 86%;
    margin: 0 auto;
    border-radius: 3rem;
    display: inline-block;
    box-sizing: border-box;
	box-shadow: 0 .3rem .8rem rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.4);
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}
.radioskin-label,.checkskin-label{margin-bottom:.8rem;display:block;width:100%;overflow:initial;word-wrap:break-word;white-space:inherit}
.radioskin-label b,.checkskin-label b{width:85%;font-size:1.4rem}
.formtips{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.1);color:<?php echo $_ZEAI['mob_mbcolor'];?>}
<?php
if ($_ZEAI['m_mb']==2){
	$mini_class='top_mini4';
	echo '.TRnav_btn i{color:'.$_ZEAI['mob_mbcolor'].'}';
}else{
	$mini_class='top_mini4 zeaibg bgcolor';
}
?>
</style>
</head>
<body>
<?php 
$mini_title='情感测试';
require_once ZEAI.'m/top_mini.php';?>
<div class="formtips">为了测试结果更为精准，以下内容请全部必填</div>
<div class="article_detail">
	<form name="ZEAIFORM" action="qinggan_detail.php" method="post">
	<?php
	$rt = $db->query("SELECT id,title,content,ifmore,subjsonstr FROM ".__TBL_LOVETEST_QUESTION__." WHERE kind=".$fid." ORDER BY id DESC");
	$total = $db->num_rows($rt);
    if ($total > 0 ) {
		for($i=1;$i<=$total;$i++) {
			$rows = $db->fetch_array($rt);
			if(!$rows) break;
			$id = $rows['id'];
			$title = dataIO($rows['title'],'out');
			$content = dataIO($rows['content'],'out');
			$ifmore = $rows['ifmore'];
			$ifmore_str = ($ifmore==1)?'<font style="font-weight:normal;" class="zeaicolor">（可多选）</font>':'';
			$jsonstr= dataIO($rows['subjsonstr'],'out');
	?>
	<li style="overflow:hidden;">
    	<p class="title"><?php echo $i."．".$ifmore_str.$title;?></p>
        <?php if(!empty($content)){?><p class="con"><?php echo $content;?></p><?php }?>
        <p class="xuanxiang">
        <?php
        $a = json_decode($jsonstr,true);
		for($j=0;$j<@count($a);$j++) {
			if($ifmore==1){?>
            <input type="checkbox" name="question<?php echo $id;?>[]" id="question<?php echo $i;?><?php echo $j+1;?>" class="checkskin" value="<?php echo $a[$j]['i'];?>:<?php echo $a[$j]['s'];?>">
            <label for="question<?php echo $i;?><?php echo $j+1;?>" class="checkskin-label"><i></i><b><?php echo $a[$j]['v'];?></b></label>
        <?php }else{?>
            <input type="radio" name="question<?php echo $id;?>[]" id="question<?php echo $i;?><?php echo $j+1;?>" class="radioskin" value="<?php echo $a[$j]['i'];?>:<?php echo $a[$j]['s'];?>"  >
            <label for="question<?php echo $i;?><?php echo $j+1;?>" class="radioskin-label"><i></i><b><?php echo $a[$j]['v'];?></b></label>
		<?php
			}
		}
		?>
        </p>
    </li>
    <?php }}else{echo"<div class='nodatatips' style='margin:0 auto'><br><br><i class='ico'>&#xe608;</i>此题库暂无试题</div>";}?> 
    </form>
    <div class="clear"></div>
</div>
<?php if ($total > 0 ) {?>
<div class="nextbtn"><button type="button" class="btn size4 B ed zeaibg" id="save">提交看结果</button></div>
<script>
save.onclick=function(){
	var escore = o('Escore');
	var answer = o('answer');
	zeai.ajax({url:'qinggan_detail.php?submitok=ajax_save&fid=<?php echo $fid;?>',form:ZEAIFORM},function(e){var rs=zeai.jsoneval(e);zeai.msg(0);
		if (rs.flag == 1){
			zeai.msg(rs.msg,{time:2});
			setTimeout(function(){zeai.openurl('qinggan_answer.php?fid=<?php echo $fid;?>');},2000);
		}else if(rs.flag == 0){
			zeai.msg(rs.msg,o(rs.focus));
			return false;
		}		
	});
}
</script>
<div id="backtop"><a href="#top" id="btmTopBtn"><i class="ico">&#xe60c;</i>顶部</a></div>
<?php }
require_once ZEAI.'m/TRnav.php';
if($_ZEAI['m_mb']==2){
	require_once ZEAI.'m/bottom2.php';
}else{
	require_once ZEAI.'m/bottom.php';
}
?>
